package com.kexun.mvc.resolvers;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Parameter;

public class IntResolver implements BaseResolver {
    @Override
    public boolean supportsParameter(Parameter parameter) {
        return parameter.getType().isAssignableFrom(int.class) || parameter.getType().isAssignableFrom(Integer.class);
    }

    @Override
    public Object resolveArgument(Parameter parameter, HttpServletRequest req, HttpServletResponse resp) {
        System.out.println("设置参数：" + parameter.getName());
        return Integer.parseInt(req.getParameter(parameter.getName()));
    }
}
